<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <meta http-equiv="Content-Style-Type" content="text/css">
  <title></title>
  <meta name="Generator" content="Cocoa HTML Writer">
  <meta name="CocoaVersion" content="824.41">
  <style type="text/css">
    p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #bf0000}
    p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica; min-height: 22.0px}
    p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica}
    p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
    p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
    p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
    p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
    span.s1 {color: #0000bf}
    span.s2 {color: #007300}
    span.s3 {color: #bf0000}
    span.s4 {color: #000000}
    span.Apple-tab-span {white-space:pre}
  </style>
</head>
<body>
<p class="p1">//SLUGens released under the GNU GPL as extensions for SuperCollider 3, by Nick Collins, http://www.informatics.sussex.ac.uk/users/nc81/</p>
<p class="p2"><b></b><br></p>
<p class="p3"><b>GravityGrid<span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>dynamical system simulation (Newtonian gravitational force)</b></p>
<p class="p2"><b></b><br></p>
<p class="p4"><b>GravityGrid.ar(reset, rate, newx, newy, bufnum, mul, add)</b></p>
<p class="p5"><br></p>
<p class="p4">Eight fixed masses around a boundary apply Newtonian gravitational force dynamics to a central moving mass which cannot escape the [-1, 1] grid in x or y. The position of the moving mass is sonified as an oscillator by its distance from the centre.<span class="Apple-converted-space">   </span></p>
<p class="p5"><br></p>
<p class="p4">This is a relatively expensive oscillator to run.<span class="Apple-converted-space"> </span></p>
<p class="p5"><br></p>
<p class="p4"><b>reset</b>- Restart the moving mass at a random position within the square (k-rate input)</p>
<p class="p4"><b>rate</b>- amount of position update per sample (k-rate)</p>
<p class="p4"><b>newx</b>- kr input to be sampled for new x positions for the moving mass on reset</p>
<p class="p4"><b>newy</b>- kr input to be sampled for new y positions for the moving mass on reset</p>
<p class="p4"><b>bufnum</b>- Bufnum for a buffer containing weights for the different outer masses indexed as 0-3 and 5-8 and central moving mass 4. Passing -1 means that the weights are not used (are flat).<span class="Apple-converted-space"> </span></p>
<p class="p5"><br></p>
<p class="p4">Note: This original GravityGrid contains an erroneous folding function, and gravity which is more attractive as the distance increases! Which however, adds interesting distortions to the sound. See GravityGrid2 for a cleaned up version. This one is retained for backwards compatibility.<span class="Apple-converted-space"> </span></p>
<p class="p6"><br></p>
<p class="p6"><br></p>
<p class="p1">//GravityGrid comes out with some interesting noisy sounds- WARNING, loud, aliasing! You'll probably want to filter the outputs, maybe with RLPF, Slew et al.</p>
<p class="p6"><br></p>
<p class="p6"><br></p>
<p class="p7">{Pan2.ar(0.05*<span class="s1">GravityGrid</span>.ar(<span class="s1">Impulse</span>.kr(2),<span class="s1">MouseX</span>.kr(0.1,10,<span class="s2">'exponential'</span>),<span class="s1">LFNoise0</span>.kr(2,0.8),<span class="s1">LFNoise0</span>.kr(2,0.8)),0.0)}.play</p>
<p class="p6"><br></p>
<p class="p6"><br></p>
<p class="p7">{Pan2.ar(0.5*<span class="s1">GravityGrid</span>.ar(<span class="s1">Impulse</span>.kr(1),<span class="s1">SinOsc</span>.kr(0.5,0.0,0.8,1.0),<span class="s1">LFSaw</span>.kr(50),<span class="s1">LFNoise0</span>.kr(10,0.8)),0.0)}.play</p>
<p class="p6"><br></p>
<p class="p1">//rhythmic violence</p>
<p class="p7">{0.1*<span class="s1">GravityGrid</span>.ar(<span class="s1">Impulse</span>.kr(<span class="s1">LFNoise0</span>.kr([0.25,0.231],90,100)),[100.2,10.5], <span class="s1">LFNoise0</span>.kr(10,0.8),<span class="s1">LFNoise0</span>.kr(10,0.8))}.play</p>
<p class="p6"><br></p>
<p class="p6"><br></p>
<p class="p1">//noisy</p>
<p class="p7">{<span class="s1">Pan2</span>.ar(<span class="s1">Resonz</span>.ar(<span class="s1">GravityGrid</span>.ar(<span class="s1">Impulse</span>.kr(50),0.01,<span class="s1">LFNoise0</span>.kr(1,4),<span class="s1">LFNoise0</span>.kr(1,4)),1000,0.1),0.0)}.play</p>
<p class="p6"><br></p>
<p class="p1">//48k spectrum looping</p>
<p class="p7">{<span class="s1">Pan2</span>.ar(<span class="s1">Resonz</span>.ar(<span class="s1">GravityGrid</span>.ar(<span class="s1">Impulse</span>.kr(5),0.01,<span class="s1">LFNoise0</span>.kr(1,4),<span class="s1">LFNoise0</span>.kr(1,4)),1000,0.1),0.0)}.play</p>
<p class="p6"><br></p>
<p class="p6"><br></p>
<p class="p7">b = <span class="s1">Buffer</span>.alloc(s, 9, 1); <span class="s3">//weights buffer</span></p>
<p class="p6"><br></p>
<p class="p7">b.setn(0,<span class="s1">Array</span>.rand(9,0.1,0.9)); <span class="s3">//set weights</span></p>
<p class="p6"><br></p>
<p class="p7">{Pan2.ar(0.1*<span class="s1">GravityGrid</span>.ar(<span class="s1">Impulse</span>.kr(1),<span class="s1">MouseX</span>.kr(0.1,1,<span class="s2">'exponential'</span>),<span class="s1">LFNoise0</span>.kr(1,0.8),<span class="s1">LFNoise0</span>.kr(1,0.8), b.bufnum),0.0)}.play</p>
<p class="p6"><br></p>
<p class="p1"><span class="s4">b.setn(0,</span><span class="s1">Array</span><span class="s4">.rand(9,0.1,0.9)); </span>//change weights to new random values</p>
<p class="p6"><br></p>
<p class="p7">b.setn(0,[0.1,1,0.1,2,0.1,3,0.1,4,0.1]); <span class="s3">//change weights to new specific values</span></p>
<p class="p6"><br></p>
<p class="p6"><br></p>
<p class="p7">{0.1*<span class="s1">Resonz</span>.ar(<span class="s1">GravityGrid</span>.ar(<span class="s1">Impulse</span>.kr(<span class="s1">LFNoise0</span>.kr([0.2,0.3],70,80)),[11.2,12.5], <span class="s1">LFNoise0</span>.kr(5.4,0.4),<span class="s1">LFNoise0</span>.kr(10,0.8), b.bufnum),<span class="s1">SinOsc</span>.ar(0.03,0,300,500),<span class="s1">SinOsc</span>.ar(0.03,0,0.3,0.4))}.play</p>
<p class="p6"><br></p>
<p class="p7">b.setn(0,[0.1,0,0.3,4,0.1,4,0.3,0,0.1]);<span class="Apple-converted-space"> </span></p>
<p class="p6"><br></p>
<p class="p7">b.setn(0,[4.1,0,6.3,4,0.1,4,0.3,0,7.1]);<span class="Apple-converted-space"> </span></p>
<p class="p6"><br></p>
<p class="p6"><br></p>
<p class="p7">{0.05*<span class="s1">GravityGrid</span>.ar(<span class="s1">Impulse</span>.kr([2,4.1]),1, <span class="s1">SinOsc</span>.kr(1,pi,0.9), <span class="s1">SinOsc</span>.kr(1.9,0,0.9),b.bufnum)}.play</p>
<p class="p6"><br></p>
<p class="p6"><br></p>
<p class="p1">//violent</p>
<p class="p7">{<span class="s1">Pan2</span>.ar(0.1*<span class="s1">GravityGrid</span>.ar(<span class="s1">Impulse</span>.ar(0),<span class="s1">MouseX</span>.kr(0.01,10,<span class="s2">'exponential'</span>)))}.play</p>
<p class="p6"><br></p>
<p class="p6"><br></p>
<p class="p6"><br></p>
<p class="p6"><br></p>
</body>
</html>
